﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using RockPaperScissors.Core;
using System.Threading.Tasks;

namespace RockPaperScissors.Web.Utility.Tests
{
    [TestFixture]
    public class ThreadTests
    {
        private MoveType CreateTimeOut(int timeout)
        {
            System.Threading.Thread.Sleep(timeout);
            return MoveType.Rock;
        }

        [Test]
        public void Method_Returns_Before_Our_Timeout()
        {
            var task = Task.Factory.StartNew (state => CreateTimeOut (5000),  MoveType.None);
            MoveType moveType = MoveType.None;

            bool copletedInTime = task.Wait(9000);
            
            if (copletedInTime == true)
                moveType = task.Result;

            Assert.IsTrue(moveType == MoveType.Rock);
        }

        [Test]
        public void Method_Returns_After_Timeout()
        {
            var task = Task.Factory.StartNew(state => CreateTimeOut(4000), MoveType.None);
            MoveType moveType = MoveType.None;

            bool copletedInTime = task.Wait(2000);

            if (copletedInTime == true)
                moveType = task.Result;


            Assert.IsTrue(moveType == MoveType.None);
        }

        //var task = Task.Factory.StartNew()
        //Console.WriteLine(task.AsyncState);   // Greeting
        //task.Wait();


        ////MoveType firstTeamResult = Utility.CompeteHelper.ProcessPlayer("firstName", @"c:\longrock.dll", new GameLog(), new RuleSet(), 1);
    }
}
